package com.sobot.finance.poc.web.controller.response;

import cn.hutool.core.util.StrUtil;
import lombok.Data;

/**
 * @author baiyp
 */
@Data
public class GeneralRes {
    private String code;
    private String message;
    private Object data;

    public final static String SUCCESS_CODE = "0000000";
    public final static String SUCCESS_MESSAGE = "操作成功";
    public final static String ERROR_SYSTEM_CODE = "9999999";
    public final static String ERROR_SYSTEM_MESSAGE = "系统异常";

    public static GeneralRes success() {
        return of(SUCCESS_CODE, SUCCESS_MESSAGE);
    }

    public boolean succeed() {
        return StrUtil.equals(code, SUCCESS_CODE);
    }

    public static GeneralRes fail() {
        return of(ERROR_SYSTEM_CODE, ERROR_SYSTEM_MESSAGE);
    }

    public static GeneralRes of() {
        return of(null, null);
    }

    public static GeneralRes of(String code, String message) {
        GeneralRes res = new GeneralRes();
        res.setCode(code);
        res.setMessage(message);
        return res;
    }
}
